﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Agile.Manager.UI.Windows.ViewModel;
using System.Windows.Threading;
using System.Threading;

namespace Agile.Manager.Windows.View
{
    /// <summary>
    /// Interaction logic for TaskDetailInfoView.xaml
    /// </summary>
    public partial class TaskDetailInfoView : UserControl
    {
        TaskDetailInfoViewModel tVM;

        public TaskDetailInfoView()
        {
            InitializeComponent();

            if (tVM == null)
                tVM = new TaskDetailInfoViewModel();

            DataContext = tVM;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("you will lose unsaved data", "Are you sure?", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
            if (result == MessageBoxResult.OK)
                CloseWindow();
        }

        public void CloseWindow()
        {

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                DependencyObject ucParent = (this).Parent;
                while (!(ucParent is Window))
                {
                    ucParent = LogicalTreeHelper.GetParent(ucParent);
                }

                (ucParent as Window).Close();
            }));
        }
    }
}
